package com.geek.bulk.echo;

import org.eclipse.microprofile.faulttolerance.CircuitBreaker;

import java.time.temporal.ChronoUnit;

public class CircuitBreakerProperties {

    private  Class<? extends Throwable>[] failOn;

    private Class<? extends Throwable>[] skipOn;

    private long delay;

    private ChronoUnit delayUnit;

    private int requestVolumeThreshold;

    private  double failureRatio;

    private int successThreshold;

    public static CircuitBreakerProperties build(CircuitBreaker circuitBreaker) {
        CircuitBreakerProperties result = new CircuitBreakerProperties();
        result.setFailOn(circuitBreaker.failOn());
        result.setSkipOn(circuitBreaker.skipOn());
        result.setDelay(circuitBreaker.delay());
        result.setDelayUnit(circuitBreaker.delayUnit());
        result.setRequestVolumeThreshold(circuitBreaker.requestVolumeThreshold());
        result.setFailureRatio(circuitBreaker.failureRatio());
        result.setSuccessThreshold(circuitBreaker.successThreshold());
        return result;
    }


    public Class<? extends Throwable>[] getFailOn() {
        return failOn;
    }

    public void setFailOn(Class<? extends Throwable>[] failOn) {
        this.failOn = failOn;
    }

    public Class<? extends Throwable>[] getSkipOn() {
        return skipOn;
    }

    public void setSkipOn(Class<? extends Throwable>[] skipOn) {
        this.skipOn = skipOn;
    }

    public long getDelay() {
        return delay;
    }

    public void setDelay(long delay) {
        this.delay = delay;
    }

    public ChronoUnit getDelayUnit() {
        return delayUnit;
    }

    public void setDelayUnit(ChronoUnit delayUnit) {
        this.delayUnit = delayUnit;
    }

    public int getRequestVolumeThreshold() {
        return requestVolumeThreshold;
    }

    public void setRequestVolumeThreshold(int requestVolumeThreshold) {
        this.requestVolumeThreshold = requestVolumeThreshold;
    }

    public double getFailureRatio() {
        return failureRatio;
    }

    public void setFailureRatio(double failureRatio) {
        this.failureRatio = failureRatio;
    }

    public int getSuccessThreshold() {
        return successThreshold;
    }

    public void setSuccessThreshold(int successThreshold) {
        this.successThreshold = successThreshold;
    }
}
